def solution(n: int) -> int:
    total_matches = 0
    while n > 1:
        if n % 2 == 0:
            matches = n // 2
            n = matches
        else:
            matches = (n - 1) // 2
            n = matches + 1
        total_matches += matches
    return total_matches

if __name__ == '__main__':
    print(solution(7) == 6)  # True
    print(solution(14) == 13)  # True
    print(solution(1) == 0)  # True